{% extends "base_site.html" %}
{% load static %}

{% block title %}Rolodex - Edit{% endblock %}

{% block extrahead %}{{ block.super }}
    <script src="{% static 'secr/js/dynamic_inlines.js' %}"></script>
{% endblock %}

{% block breadcrumbs %}{{ block.super }}
    &raquo; <a href="../../">Rolodex</a>
    &raquo; <a href="../">{{ person }}</a>
    &raquo; Edit
{% endblock %}

{% block content %}
    <form enctype="multipart/form-data" method="post" id="rolodex-edit-form">{% csrf_token %}
        <div class="module">
            <h2>Rolodex - Edit</h2>
            <table id="rolodex-edit-table" class="full-width amstable">
                <tbody>
                <!-- [html-validate-disable-block wcag/h63 -- FIXME: as_table renders without scope] -->
                {{ person_form.as_table }}
                </tbody>
            </table>

            <div class="inline-group">
                <div class="tabular inline-related">
                    <h2>Email Addresses</h2>
                    {{ email_formset.management_form }}
                    {{ email_formset.non_form_errors }}
                    <table id="rolodex-email-table" class="full-width">
                        <thead>
                            <tr>
                                <th scope="col"></th>
                                {% for field in email_formset.forms.0 %}
                                    {% if not field.is_hidden %}
                                        <th scope="col">{{ field.label }}</th>
                                    {% endif %}
                                {% endfor %}
                            </tr>
                        </thead>
                        <tbody>
                            {% for form in email_formset.forms %}
                                {% if form.non_field_errors %}{{ form.non_field_errors }}{% endif %}
                                <tr class="dynamic-inline {% cycle 'row1' 'row2' %}">
                                    <td>
                                    {# Include the hidden fields in the form #}
                                    {% for hidden in form.hidden_fields %}
                                        {{ hidden }}
                                    {% endfor %}
                                    </td>
                                    {% for field in form.visible_fields %}
                                        <td>
                                            {{ field.errors }}
                                            {{ field }}
                                        </td>
                                    {% endfor %}
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div> <!-- inline-related last_related -->

            {% include "includes/buttons_save_cancel.html" %}

        </div> <!-- module -->
    </form>


{% endblock %}